#include "linklist.h"

// 创建新节点
list* createNode(int data) {
    list* newNode = (list*)malloc(sizeof(list));
    if (newNode == NULL) {
        printf("内存分配失败\n");
        exit(1);
    }
    newNode->data = data;
    newNode->next = NULL; 
    return newNode;
}

// 尾插法构建链表
list* tailInsertion(list* newNode,int data) {
    list* head = NULL;
    list* tail = NULL;
 
    printf("请输入链表节点的数据(输入-1结束输入):\n");
    while (1) {
        scanf("%d", &data);
        if (data == -1) {
            break;
        }
       list* newNode = createNode(data);
        if (head == NULL) {
            head = newNode;
            tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }

    return head;
}

// 打印链表
void printList(list* head) {
    if (head == NULL) {
        printf("链表为空\n");
        return;
    }

    printf("链表节点数据为：\n");
    while (head != NULL) {
        printf("%d ", head->data);
        head = head->next;
    }
    printf("\n");
}


int deletehead(list* head)
{
     if (head == NULL) {
        printf("链表为空\n");
        return -1;
    }
    list * temp = head ->next;
    int deletedata = temp ->data;
    head ->next = temp ->next;
    if(temp!=NULL)
    {   
        
    }
    return deletedata;
}